package com.hs.service.impl;

import com.hs.entity.pojo.Tag;
import com.hs.entity.pojo.Trend;
import com.hs.mapper.TagMapper;
import com.hs.service.TagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.service.TrendService;
import com.hs.utils.ResultResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hs
 * @since 2023-08-05
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    @Resource
    private TrendService trendService;

    @Override
    public ResultResponse<List<Tag>> getAllTags() {
        // 查询动态所有存在的标签，有的标签就显示，没有的就不显示
        List<Trend> trends = trendService.list();

        List<Integer> tagIds = trends
                .stream().map(Trend::getTagId)
                .distinct().collect(Collectors.toList());

        List<Tag> tags = query().in("id", tagIds).list();
        return ResultResponse.ok(tags);
    }
}
